package day01;

/**
 * @Author Stringzhua
 * @Date 2024/10/29 11:31
 * description:
 */
public class Test09 {
    public static void main(String[] args) {
        // 创建子线程
        Thread thread = new Thread() {
            public void run() {
                System.out.println("子线程开始执行，进入RUNNABLE状态");
                try {
                    // 子线程休眠6秒，进入TIMED_WAIT计时等待状态
                    Thread.sleep(1000 * 6);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    System.out.println("子线程中断，进入TERMINATED状态");
                    return;
                }
                System.out.println("子线程结束执行，进入TERMINATED状态");
            }
        };

        // 启动子线程
        thread.start();

        // main主线程休眠5秒
        try {
            Thread.sleep(1000 * 3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // main主线程修改子线程的中断状态=true
        // 子线程检测中断状态=true，则抛出InterruptedException，子线程执行结束
        thread.interrupt();
    }
}